home *** CD-ROM | disk | FTP | other *** search
- Path: Inter.NL.net!usenet
- From: Auke.Reitsma@net.HCC.nl (Auke Reitsma)
- Newsgroups: comp.lang.c,comp.lang.c++,comp.lang.c++.leda
- Subject: Re: Common var Pbs
- Date: Tue, 02 Apr 1996 20:16:07 GMT
- Organization: Inter.NL.net, The Internet Provider in The Netherlands.
- Message-ID: <4js1un$568@altrade.nijmegen.inter.nl.net>
- References: <3160642C.7606@green-uhp.u-nancy.fr>
- Reply-To: Auke.Reitsma@net.HCC.nl
- NNTP-Posting-Host: rt99-20.rotterdam.nl.net
- X-Newsreader: Forte Free Agent 1.0.82
-
- Lotfi BAGHLI <baghli@green-uhp.u-nancy.fr> wrote:
-
- > I have problems when linking 3 cpp files which use common
- > variables and constants
- > in a BC++4.5 / OWL 2.5 application :
-
- Even though your stuff is C++, it is a common problem in C too.
- I cleaned the following quotes a bit ...
-
- > A:
- > ------ A.H
- > --------
- > enum Jour { Lundi, Mardi, Mercredi, ... , Dimanche };
-
- OK.
-
- > HBITMAP JourImage[Dimanche+1][4];
-
- replace this by:
-
- extern HBITMAP JourImage[Dimanche+1][4];
-
- > const int Periode[Dimanche+1]={ 4, 2, 0, 4, 4, 4, 0};
-
- repalce this by:
-
- extern const int Periode[Dimanche+1];
-
- > const char * JourName[Dimanche+1]= { "Lundi", "Mardi", ..., "Dimanche" };
-
- replace this by:
-
- extern const char * JourName[Dimanche+1];
-
- > class TJour {...};
- > typedef TIArrayAsVector <TJour> TJourCollection;
-
- > A.CPP
- > --------
- > #include "A.H"
- > methods of TJour ...
-
- Add here:
-
- HBITMAP JourImage[Dimanche+1][4];
- const int Periode[Dimanche+1]={ 4, 2, 0, 4, 4, 4, 0};
- const char * JourName[Dimanche+1]= { "Lundi","Mardi", ...,"Dimanche"};
-
-
- > The linking generates errors :
- > _JourImage defined in module A.CPP is duplicated in module B.CPP
-
- The problem is that you were reserving space for variables, which is
- something you should only do in .c(pp) files, and NEVER in .h(pp) files.
- The 'extern' in the .h prevents the problem.
-
- I.e.: use extern XXX in .h files and XXX = some_value in .c files. With
- XXX the same thing for both.
-
- Greetings from Delft, The Netherlands,
- Auke Reitsma.
-
-